const Router = require("koa-router");

const {
  userValidator,
  verifyUser,
  cryptPassword,
  verifyLogin,
  hasVerificationCode,
  hasUser
  
} = require("../middleware/user.middleware");

const { auth, hasAdminPermission } = require("../middleware/auth.middleware");
const {
  register,
  login,
  updataUserInfo,
  getUserInfo,
  getUserList,
  verifyCodeLogin,
} = require("../controller/user/user.controller");
const router = new Router({ prefix: "/users" });

router.post("/register", userValidator, verifyUser, cryptPassword,hasVerificationCode, register); // 注册
router.post("/login", verifyLogin, login); // 登录
router.post("/verify-code-login",hasUser, hasVerificationCode, verifyCodeLogin); // 验证码登录
// router.put("/updata-userInfo", auth, cryptPassword, updataUserInfo);
router.put("/updata-userInfo", auth, updataUserInfo); // 更新用户信息
router.get("/get-userInfo", auth, getUserInfo); // 获取用户信息
router.get("/get-userList", auth, hasAdminPermission, getUserList); // 获取用户列表

module.exports = router;
